var mapIds = [993173700];
var 准备地图 = 993123000;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("荣耀活动_支援塞尔提乌_解救骑士团");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    c.schedule("骑士准备", 1 * 1000);
    return c
}

function 骑士准备(a) {
    var b = a.getMapInstance(0);
    b.killAllMonsters(false);
    a.getPlayers().forEach(function (c) {
        c.getAPI().glorySaveKnightsTime(0, 10000)
    });
    a.schedule("骑士出场", 10 * 1000)
}

function 骑士出场(a) {
    var b = a.getMapInstance(0);
    b.spawnMonsterOnGroundBelow(em.getMonster(9833692), new java.awt.Point(-955, -513));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833692), new java.awt.Point(-955, -97));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833692), new java.awt.Point(-20, -299));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833692), new java.awt.Point(977, -511));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833692), new java.awt.Point(977, -89));
    a.getPlayers().forEach(function (c) {
        c.getAPI().glorySaveKnightsHP(0, 100);
        c.getAPI().glorySaveKnightsHP(1, 100);
        c.getAPI().glorySaveKnightsHP(2, 100);
        c.getAPI().glorySaveKnightsHP(3, 100);
        c.getAPI().glorySaveKnightsHP(4, 100);
        c.getAPI().getWeatherEffectNotice("塞尔提乌骑士受到了攻击！请保护骑士们的安危！", 297, 3000, 1);
        c.getAPI().glorySaveKnightsTime(1, 115000);
        c.getAPI().glorySaveKnightsState(1, 0);
        c.getAPI().glorySaveKnightsState(1, 1);
        c.getAPI().glorySaveKnightsState(1, 2);
        c.getAPI().glorySaveKnightsState(1, 3);
        c.getAPI().glorySaveKnightsState(1, 4)
    });
    a.schedule("骑士离开", 115 * 1000);
    a.schedule("士兵出没", 0 * 1000);
    a.schedule("暗杀兵出没", 40 * 1000);
    a.schedule("暗杀兵出没", 70 * 1000);
    a.schedule("暗杀兵出没", 100 * 1000);
    a.schedule("魔法师出没", 85 * 1000)
}

function 士兵出没(a) {
    var b = a.getMapInstance(0);
    b.spawnMonsterOnGroundBelow(em.getMonster(9833693), new java.awt.Point(-955 + a.rand(-200, 200), -513));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833693), new java.awt.Point(-955 + a.rand(-200, 200), -97));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833693), new java.awt.Point(-20 + a.rand(-200, 200), -299));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833693), new java.awt.Point(977 + a.rand(-200, 200), -511));
    b.spawnMonsterOnGroundBelow(em.getMonster(9833693), new java.awt.Point(977 + a.rand(-200, 200), -89));
    a.schedule("士兵出没", 12 * 1000)
}

function 暗杀兵出没(a) {
    var b = a.getMapInstance(0);
    var c = a.rand(0, 4);
    switch (c) {
        case 0:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833694), new java.awt.Point(-955 + a.rand(-200, 200), -513));
            break;
        case 1:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833694), new java.awt.Point(-955 + a.rand(-200, 200), -97));
            break;
        case 2:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833694), new java.awt.Point(-20 + a.rand(-200, 200), -299));
            break;
        case 3:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833694), new java.awt.Point(977 + a.rand(-200, 200), -511));
            break;
        case 4:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833694), new java.awt.Point(977 + a.rand(-200, 200), -89));
            break
    }
    a.getPlayers().forEach(function (d) {
        d.getAPI().addPopupSay(9062210, 2000, "附近有暗杀兵出没！为防止骑士受到巨大伤害，请速速消灭他们！", "", 1);
        d.getAPI().glorySaveKnightsState(2, c)
    })
}

function 魔法师出没(a) {
    var b = a.getMapInstance(0);
    switch (a.rand(1, 4)) {
        case 1:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833695), new java.awt.Point(-30, -721));
            break;
        case 2:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833695), new java.awt.Point(-30, 59));
            break;
        case 3:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833695), new java.awt.Point(-1802, -299));
            break;
        case 4:
            b.spawnMonsterOnGroundBelow(em.getMonster(9833695), new java.awt.Point(1782, -307));
            break
    }
    a.getPlayers().forEach(function (c) {
        c.getAPI().addPopupSay(9062210, 2000, "高等翼人魔法师出现了。必须要在他施展魔法前将其消灭！", "", 1);
        c.getAPI().glorySaveKnightsAttack(0)
    });
    a.schedule("魔法师攻击", 10 * 1000)
}

function 魔法师攻击(a) {
    var b = a.getMapInstance(0);
    if (b.countMonsterById(9833695) == 0) {
        return
    }
    a.getPlayers().forEach(function (c) {
        c.getAPI().addPopupSay(9062210, 2000, "魔法师使骑士们受到了巨大伤害！魔法师出现时，请率先消灭魔法师！", "", 1);
        c.getAPI().glorySaveKnightsAttack(1)
    })
}

function 骑士离开(b) {
    var c = b.getMapInstance(0);
    var a = c.countMonsterById(9833692);
    b.getPlayers().forEach(function (d) {
        d.getAPI().glorySaveKnightsSuccess();
        d.getAPI().glorySaveKnightsState(0, 0);
        d.getAPI().glorySaveKnightsState(0, 1);
        d.getAPI().glorySaveKnightsState(0, 2);
        d.getAPI().glorySaveKnightsState(0, 3);
        d.getAPI().glorySaveKnightsState(0, 4);
        d.getAPI().addPopupSay(9062210, 2000, "已将" + a + "位骑士安全移送至塞尔提乌！", "", 1);
        d.getAPI().addNumberForQuestInfo(100353, "save", a)
    });
    b.schedule("骑士准备", 1 * 1000)
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    em.setProperty("kill", "0");
    em.setProperty("level", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a);
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onMonsterDamaged(b, a, d, e, c) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, f, c) {
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a);
    if (f == 9833694) {
        var e = [
            [-955, -513],
            [-955, -97],
            [-20, -299],
            [977, -511],
            [977, -89]
        ];
        var g = 0;
        var d = player.getMap().getMonsterByOid(c);
        for (; g < e.length; g++) {
            if (d.getPosition().distance(e[g][0], coord[g][1]) < 350) {
                b.getPlayers().forEach(function (h) {
                    h.getAPI().glorySaveKnightsState(1, g)
                });
                break
            }
        }
    }
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};